package jeconbond.economic.agent;

import jeconbond.economic.agent.BaseEconProdDecoratod;
import jeconbond.economic.agent.IEconomicProducer;
import jeconbond.economic.agent.service.IPreActServiceAgent;

public class ActIFFinRangeOfStepsAgent extends BaseEconProdDecoratod {
	private int[] sharedStepCounter;
	private int rangeBegin;
	private int rangeEnd;
	
	public ActIFFinRangeOfStepsAgent(
			IEconomicProducer subagent,
			int[] sharedStepCounter, 
			int rangeBegin, 
			int rangeEnd
	) {
		super(subagent);
		this.sharedStepCounter = sharedStepCounter;
		this.rangeBegin = rangeBegin;
		this.rangeEnd = rangeEnd;
	}

	@Override
	public void processProduceStage() {
		if (actableNow()) {
			subagent.processProduceStage();
		}
	}

	@Override
	public void processPreProduceStage() {
		if (actableNow()) {
			subagent.processPreProduceStage();
		}
	}
	
	@Override
	public void processPostProduceStage() {
		if (actableNow()) {
			subagent.processPostProduceStage();
		}
	}

	private boolean actableNow() {
		int stepCounter = sharedStepCounter[0];
		return (stepCounter >= rangeBegin) && (stepCounter <= rangeEnd);
	}

	public static class PreService extends ActIFFinRangeOfStepsAgent implements IPreActServiceAgent {
		public PreService(
			IEconomicProducer subagent,
			int[] sharedStepCounter,
			int rangeBegin,
			int rangeEnd
		) {
			super(subagent, sharedStepCounter, rangeBegin, rangeEnd);
		}
	}
}
